<template>
  <div ref="dom" class="linecharts"></div>
</template>

<script>
import echarts from "echarts";
const off = (function () {
  if (document.removeEventListener) {
    return function (element, event, handler) {
      if (element && event) {
        element.removeEventListener(event, handler, false);
      }
    };
  } else {
    return function (element, event, handler) {
      if (element && event) {
        element.detachEvent("on" + event, handler);
      }
    };
  }
})();
const on = (function () {
  if (document.addEventListener) {
    return function (element, event, handler) {
      if (element && event && handler) {
        element.addEventListener(event, handler, false);
      }
    };
  } else {
    return function (element, event, handler) {
      if (element && event && handler) {
        element.attachEvent("on" + event, handler);
      }
    };
  }
})();
export default {
  name: "ChartLine",
  props: {
    lineDataX: Array,
    lineDataY: Array,
  },
  data() {
    return {
      dom: null,
    };
  },
  methods: {
    resize() {
      this.dom.resize();
    },
  },
  mounted() {
    this.$nextTick(() => {
      let option = {
        xAxis: {
          type: "category",
          data: this.lineDataX,
            axisLabel: {
              interval: 0,
              rotate: 40,
              color: '#000000'
            },
        },
        yAxis: {
          type: "value",
        },
        lineStyle: {
          color: "#5B8FF9",
        },

        series: [
          {
            data: this.lineDataY,
            type: "line",
          },
        ],
      };
      this.dom = echarts.init(this.$refs.dom);
      this.dom.setOption(option);
      on(window, "resize", this.resize);
    });
  },
  beforeDestroy() {
    off(window, "resize", this.resize);
  },
};
</script>
<style lang="scss" scoped>
.linecharts {
  height: 90%;
}
</style>
